/*
 * cubeIO.h
 *
 * Handles:
 *  - reading/writing of plain text cube states
 *  - Reading/writing of mmapped cube heuristic tables
 *
 *  Created on: Sep 27, 2013
 *
 * @author Daniel Rogers
 */

#ifndef CUBEIO_H_
#define CUBEIO_H_

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
#include <sys/stat.h>

#include "utils.h"
#include "cube.h"

/*
 * Reads in a plain text file as a cube state and validates it
 *
 * @param[in] fname The file to read from
 * @param[out] state The cube state to write to (if the state is valid)
 *
 * @return true if the file could be loaded, and it was a valid state
 *
 */
bool loadCubeFromFile(const char * fname, Cube * state, uint8_t * htables[3]);

/*
 * Reads in the files containing the corner and edge cubie heuristic data
 *
 * @param[out] htables An array of pointers that the heuristic tables will be
 *                      loaded into. This will malloc the appropriate amnt. of
 *                      memory, so make sure to free the memory when done.
 *
 * @return true if the files could be loaded
 */
bool loadHTables(uint8_t * htables[3]);

/*
 * Frees the memory used by the heuristic tables
 * After return, the pointers passed in will be NULL
 *
 * @param htables An array of pointers to the heuristic table arrays
 */
void freeHTables(uint8_t * htables[3]);

#endif /* CUBEIO_H_ */
